<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <base href="<%=basePath%>"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>AnonyEast's 新闻门户</title>
    <link href="css/main.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
    <script type="text/javascript" src="js/index_topicNews.js"></script>
    <script type="text/javascript">
        function check() {
            var login_username = document.getElementById("uname");
            var login_password = document.getElementById("upwd");
            if (login_username.value == "") {
                alert("用户名不能为空！请重新填入！");
                login_username.focus();
                return false;
            } else if (login_password.value == "") {
                alert("密码不能为空！请重新填入！");
                login_password.focus();
                return false;
            }
            return true;
        }

        function focusOnLogin() {
            var login_username = document.getElementById("uname");
            login_username.focus();
        }
    </script>
</head>

<body onload="focusOnLogin()">

<div id="header">
    <div id="top_login">
        <form action="userServlet/news" method="post" onsubmit="return check()">
            <input type="hidden" name="method" value="login"/>
            <label> 登录名 </label>
            <input type="text" name="uname" value="" id="uname" class="login_input"/>
            <label> 密&#160;&#160;码 </label>
            <input type="password" name="upwd" value="" id="upwd" class="login_input"/>
            <input type="submit" class="login_sub" value="登录"/>
            <label id="error" style="color: red">${loginError_msg}</label>
            <a href="indexServlet" class="login_link">返回首页</a>
            <img src="images/friend_logo.gif" alt="Google" id="friend_logo"/>
        </form>
    </div>
    <div id="nav">
        <div id="logo"><a href="indexServlet"><img src="images/logo.jpg" alt="新闻中国" /></a></div>
        <div id="a_b01"><img src="images/a_b01.gif" alt=""/></div>
        <!--mainnav end-->
    </div>
</div>

<div id="container">
    <div style="float: left;width: 157px;">
        <%@ include file="index-elements/index_sidebar.jsp" %>
    </div>
    <!-- 容纳左侧最新消息的容器 -->

    <div class="main">
        <div class="class_type"><img src="images/class_type.gif" alt="新闻中心"/></div>
        <div class="content">
            <ul class="class_date">
                <!-- 新闻主题链接区域 -->
                <%--使用jstl处理集合数据--%>
                <c:forEach items="${allTopic}" var="topic" varStatus="i">
                    <a href="newsServlet?method=getIndexByTopic&pageNo=1&size=20&tid=${topic.tid}"
                       class="topic"><b>${topic.tname}</b></a>
                    <c:if test="${i.count % 9 == 0}">
                        <li id="class_month"></li>
                    </c:if>
                </c:forEach>
            </ul>
            <ul class="classlist">
                <!-- 分页显示新闻区域 -->
                <%--判断是否有新闻数据--%>
                <c:choose>
                    <c:when test="${empty newsList}">
                        <li>暂无新闻数据</li>
                    </c:when>
                    <c:otherwise>
                        <c:forEach items="${newsList}" var="news">
                            <li>
                                <a href="newsServlet?method=readNews&nid=${news.nid}">${news.ntitle}</a>
                                <span>${news.nmodifyDate}</span>
                            </li>
                        </c:forEach>
                    </c:otherwise>
                </c:choose>

                <c:if test="${not empty newsList}">
                    <p align="center" style="font-size: 14px;">第${pageNo}页 共${totalPages}页</p>
                </c:if>
                <a href="newsServlet?method=getIndexByTopic&pageNo=1&size=20&tid=0">全部</a>
                <c:if test="${pageNo != 1}">
                    <a href="newsServlet?method=getIndexByTopic&pageNo=1&size=20&tid=${tid}">首页</a>
                </c:if>
                <c:if test="${pageNo != 1}">
                    <a href="newsServlet?method=getIndexByTopic&pageNo=${pageNo-1}&size=20&tid=${tid}">上一页</a>
                </c:if>
                <c:set var="totalPagesValue" value="${totalPages}"/>
                <c:if test="${pageNo != totalPagesValue && totalPagesValue != 0}">
                    <a href="newsServlet?method=getIndexByTopic&pageNo=${pageNo+1}&size=20&tid=${tid}">下一页</a>
                </c:if>
                <c:if test="${pageNo != totalPagesValue && totalPagesValue != 0}">
                    <a href="newsServlet?method=getIndexByTopic&pageNo=${totalPages}&size=20&tid=${tid}">末页</a>
                </c:if>
            </ul>
        </div>
        <div class="picnews">
            <ul>
                <li> <a href="https://www.anonyeast.top/27/" target="_blank"><img src="images/pic(5).jpg" width="249" alt="" /> </a><a href="https://www.anonyeast.top/27/" target="_blank">JavaSE笔记：面向对象篇</a> </li>
                <li> <a href="https://www.anonyeast.top/221/" target="_blank"><img src="images/pic(2).jpg" width="249" alt="" /> </a><a href="https://www.anonyeast.top/221/" target="_blank">JavaSE笔记：开发基础篇</a> </li>
                <li> <a href="https://www.anonyeast.top/584/" target="_blank"><img src="images/pic(1).jpg" width="249" alt="" /> </a><a href="https://www.anonyeast.top/584/" target="_blank">JavaSE笔记：进阶篇</a> </li>
                <li> <a href="https://www.anonyeast.top/1037/" target="_blank"><img src="images/pic(4).jpg" width="249" alt="" /> </a><a href="https://www.anonyeast.top/1037/" target="_blank">JDBC：Druid连接池和JdbcTemplate</a> </li>
            </ul>
        </div>
    </div>
</div>
<%@ include file="index-elements/index_bottom.html" %>
</body>
</html>